<html>

<head>
  <script src="./ffmpeg.min.js"></script>
  <style>
    html,
    body {
      margin: 0;
      width: 100%;
      height: 100%;
    }

    body {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
  </style>
</head>

<body>
  <h3>Select multiple video files to Concatenate</h3>
  <video id="output-video" controls></video><br />
  <input type="file" id="uploader" multiple />
  <p id="message"></p>
  <script>
    const { createFFmpeg, fetchFile } = FFmpeg;
    const ffmpeg = createFFmpeg({ log: true });

    const transcode = async ({ target: { files } }) => {
      const message = document.getElementById("message");
      message.innerHTML = "Loading ffmpeg-core.js";
      await ffmpeg.load();
      message.innerHTML = "Start Concating";
      const inputPaths = [];
      for (const file of files) {
        const { name } = file;
        ffmpeg.FS('writeFile', name, await fetchFile(file));
        inputPaths.push(`file ${name}`);
      }
      ffmpeg.FS('writeFile', 'concat_list.txt', inputPaths.join('\n'));
      await ffmpeg.run('-f', 'concat', '-safe', '0', '-i', 'concat_list.txt', 'output.mp4');
      message.innerHTML = "Complete Concating";
      const data = ffmpeg.FS('readFile', 'output.mp4');
      const video = document.getElementById("output-video");
      video.src = URL.createObjectURL(
        new Blob([data.buffer], {
          type: "video/mp4"
        })
      );
      video.play();
    };
    const elm = document.getElementById("uploader");
    elm.addEventListener("change", transcode);
  </script>
</body>

</html>